<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改资料爬取')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-spider-edit" th:object="${materialSpider}">
            <input id="id" name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">上级目录：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="pid" type="hidden" th:field="*{pid}" />
                        <input class="form-control" type="text" onclick="selectSpiderTree()" id="treeName" readonly="true" th:field="*{parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <input name="content" th:field="*{content}" class="form-control" type="hidden">
                    <div id="editor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "dict/spider";

        $("#form-spider-edit").validate({
            focusCleanup: true
        });

        $(function() {
			$('.summernote').summernote({
				placeholder : '请输入内容',
				height : 400,
				lang : 'zh-CN',
				followingToolbar : false,
				callbacks : {
					onImageUpload : function(files) {

					}
				}
			});
			var content = $("#content").val();
			$('#editor').summernote('code', content);
		});

        function submitHandler() {
            if ($.validate.form()) {
                var sHTML = $('.summernote').summernote('code');
				$("#content").val(sHTML);
                $.operate.save(prefix + "/edit", $('#form-spider-edit').serialize());
            }
        }

        function importHandler() {
            var id = $('#id').val();
            var importToMaterialUrl = prefix + "/material/" + id;
       		$.modal.open("导入&创建学习资料", importToMaterialUrl);
        }

        /*资料爬取-新增-选择父部门树*/
        function selectSpiderTree() {
            var options = {
                title: '资料爬取选择',
                width: "380",
                url: prefix + "/selectSpiderTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#treeId").val(body.find('#treeId').val());
               $("#treeName").val(body.find('#treeName').val());
               layer.close(index);
        }
    </script>
</body>
</html>